# 1 创建客户端socket, client_socket
# 2 和服务器套接字建立连接 connect(ip, port)
# 3 发送数据 send()
# 4 接受数据 recv()
# 5 关闭客户端套接字 close()

import socket
# 1 创建客户端socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 2 和服务器套接字建立连接 connect(ip, port)
ip = '127.0.0.1'
port = 8888
client_socket.connect((ip, port))

# 3 发送数据 send()
client_socket.send('你好'.encode('utf-8'))

# 4 接受数据 recv()
recv_data = client_socket.recv(1024)
print(recv_data.decode('utf-8'))

# 5 关闭客户端套接字 close()
client_socket.close()
print('客户端关闭连接')

